﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace RaonaShowcase
{
    public partial class FlipElement : UserControl
    {
        private bool _front = true;
		private string title="";
		private string frontimg="";
		private string backimg="";
		private string slogan="";
		private string description="";
		private string tag1="";
		private string tag2="";
		private string tag3="";
		private string logoimg="";
		private string urllink="";
		private int count=0;
		
		public event EventHandler<EventArgs> FlipLoaded = null;

		
		public string Title
        {
            get { return title; }
            set {
                title = value;
                this.txtTitleFront.Text = title;
				this.txtTitleBack.Text = title;
            }
        }

		public string FrontImgPath
        {
            get { return frontimg; }
            set {
                frontimg = value;
                this.imgFront.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(frontimg, UriKind.RelativeOrAbsolute));
            }
        }	
		
		public string BackImgPath
        {
            get { return backimg; }
            set {
                backimg = value;
                this.imgBack.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(backimg, UriKind.RelativeOrAbsolute));
            }
        }	

		public string LogoImgPath
        {
            get { return logoimg; }
            set {
                logoimg = value;
                this.imgLogo.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(logoimg, UriKind.RelativeOrAbsolute));
            }
        }			
		public string Slogan
        {
            get { return slogan; }
            set {
                slogan = value;
                this.txtSlogan.Text = slogan;
            }
        }

		public string Description
        {
            get { return description; }
            set {
                description = value;
                this.txtDescription.Text = description;
            }
        }

		public string Tag1
        {
            get { return tag1; }
            set {
                tag1 = value;
                this.txtTag1.Text = tag1;
            }
        }

		public string Tag2
        {
            get { return tag2; }
            set {
                tag2 = value;
                this.txtTag2.Text = tag2;
            }
        }		
		
		public string Tag3
        {
            get { return tag3; }
            set {
                tag3 = value;
                this.txtTag3.Text = tag3;
            }
        }		

		public string UrlLink
        {
            get { return urllink; }
            set {
                urllink = value;
                this.urlLink.NavigateUri = new Uri(urllink, UriKind.RelativeOrAbsolute);
            }
        }	
		
        public FlipElement()
        {
            InitializeComponent();
            this.grdScreens.MouseLeftButtonDown += new MouseButtonEventHandler(grdScreens_MouseLeftButtonDown);
			this.brdFrontTitle.MouseEnter += new MouseEventHandler(txtTitleFront_MouseEnter);
			this.brdFrontTitle.MouseLeave += new MouseEventHandler(txtTitleFront_MouseLeave);
			this.txtSlogan.MouseEnter += new MouseEventHandler(txtSlogan_MouseEnter);
			this.txtSlogan.MouseLeave += new MouseEventHandler(txtSlogan_MouseLeave);
			this.imgBack.ImageOpened +=new System.EventHandler<System.Windows.RoutedEventArgs>(ImageOpened);
			this.imgFront.ImageOpened +=new System.EventHandler<System.Windows.RoutedEventArgs>(ImageOpened);
			this.imgLogo.ImageOpened +=new System.EventHandler<System.Windows.RoutedEventArgs>(ImageOpened);
			this.Visibility= Visibility.Collapsed;
        }

        void grdScreens_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (_front)
            {
                AnimateFlipForward.Begin();
                _front = false;
            }
            else
            {
                AnimateFlipReverse.Begin();
                _front = true;
            }
        }

        void txtTitleFront_MouseEnter(object sender, MouseEventArgs e)
        {
                TitleGrowth.Begin();
        }
		
        void txtTitleFront_MouseLeave(object sender, MouseEventArgs e)
        {
                TitleReduce.Begin();
        }

		void txtSlogan_MouseEnter(object sender, MouseEventArgs e)
        {
                SloganColorChange.Begin();
        }

		void txtSlogan_MouseLeave(object sender, MouseEventArgs e)
        {
                SloganColorUndo.Begin();
        }	
		
        private void ImageOpened(object sender, System.Windows.RoutedEventArgs e)
        {
        		count++;
			
				if(count==3) {
					this.Visibility= Visibility.Visible;
					if(this.FlipLoaded!=null) this.FlipLoaded(this, EventArgs.Empty);
				}			
        }

    }
}

	